package net.xdclass.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.xdclass.exception.BizException;
import net.xdclass.model.AddressDO;
import net.xdclass.service.AddressService;
import net.xdclass.util.JsonData;
import net.xdclass.enums.BizCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 电商-公司收发货地址表 前端控制器
 * </p>
 *
 * @author zhaolei
 * @since 2025-10-10
 */
@Api(tags = "电商-收货地址模块")
@RestController
@RequestMapping("/api/address/v1/")
public class AddressController {

    @Autowired
    private AddressService addressService;

    @ApiOperation("根据id查找地址详情")
    @GetMapping("/detail/{address_id}")
    public JsonData detail(
            @ApiParam(value = "地址id",required = true)
            @PathVariable("address_id") long addressId) {
        AddressDO addressDO = addressService.detail(addressId);
//        int i = 1 / 0;
        return JsonData.buildSuccess(addressDO);
        //不管接口的返回值是什么，都可以抛出任何异常
//        throw new BizException(BizCodeEnum.CODE_CAPTCHA);
    }

    /**
     * 通过地址 http://localhost:9001/api/address/v1/detail?addressId=1 调用
     * 通过问号分隔参数，不用 PathVariable
     * @param addressId
     * @return
     */
    @ApiOperation("通过地址id查询地址详情通过问号拼接参数")
//    @RequestMapping("/detail")    //这个标签用的不准确
    @GetMapping("/detail")
    public AddressDO detail1(long addressId) {
        return addressService.detail(addressId);
    }

    @ApiOperation("获取全部地址数据")
    @GetMapping("/listAll")
    public List<AddressDO> listAll() {
        return addressService.listAll();
    }
}
